package implementation;
import GameData.*;

import protocol.Query;
import protocol.State;
import protocol.StateObject;

public class RecapHandler {

	public static String generateRecap(Query q)
	{
		TicketAggregate ta = q.getTicketInfo();
		Game g = q.getGameInfo();
		String recapPrompt = "Recap%" +
			ta.numTickets + "," +
			ta.costPerTicket + "," +
			g.homeTeam + "," +
			g.awayTeam + "," +
			g.getDate() + "," +
			g.time + "," +
			ta.section + "," +
			ta.sectionNum;
		return recapPrompt;
	}
	
	public static void handleRecap(StateObject nextState, Query query) {
		System.out.println("recap handler");
		
		/*
		 * Set up the initial query
		 */
//		String numTix = query.getNumTix();
//		String price = "95";
//		String homeTeam = query.getHomeTeam();
//		String awayTeam = query.getAwayTeam();
//		String date = query.getDate();
//		String time = "1:05"; //get from the database
//		String seating = "field level"; //get from the database
//		String section = "24"; //get from the database
//		
//		String standardPrompt = "Recap%" + 
//		numTix + "," +
//		price + "," +
//		homeTeam + "," +
//		awayTeam + "," +
//		date + "," +
//		time + "," +
//		seating + "," +
//		section;
//		numTix + "," +
//		price + "," +
//		homeTeam + "," +
//		awayTeam + "," +
//		date + "," +
//		time; + "," +
//		seating + "," +
//		section;
		
		String standardPrompt = generateRecap(query); 
		String helpPrompt = "RecapHelp";
		
		/*
		 * Play the initial query
		 */
		ExecUtils.playPrompt(standardPrompt, nextState);
		
		/*
		 * Ask for a response until the user says something
		 */
		boolean receivedInput = false;
		while(!receivedInput)
		{
			ExecUtils.getUserInput(query, "gram_recap");
			String shortConf = query.getShortConf().trim().toLowerCase();
			
			if(shortConf != null)
			{
				// Check if user says YES (or something like it)
				if(shortConf.equals("yes") ||
						shortConf.equals("i agree") ||
						shortConf.equals("purchase"))
				{
					receivedInput = true;
					nextState.setState(State.CLOSING);
				}
				
				// Check for STARTOVER or RESTART
				else if(shortConf.equals("startover") || shortConf.equals("start over") ||
						shortConf.equals("restart"))
				{
					receivedInput = true;
					nextState.setState(State.NUMTIX);
				}
					
				// Check for GOBACK
				else if(shortConf.equals("goback") || shortConf.equals("go back"))
				{
					receivedInput = true;
					nextState.setState(State.PRICE);
				}
				
				// Check for HELP
				else
					ExecUtils.playPrompt("RecapHelp", nextState);
			}
			else
				ExecUtils.playPrompt(helpPrompt, nextState);
			query.voidTransaction();
		}
	}
}
